// components/UserDialog.tsx
import React, { useEffect, useState } from 'react';
import {
  Dialog, DialogTitle, DialogContent
} from '@mui/material';
import UserCRUDForm from './UserCRUDForm';

type User = {
  id?: number;
  userId: string;
  name: string;
  department: string;
  role: string;
};

type Props = {
  open: boolean;
  user?: User | null;
  onClose: () => void;
  onSubmit: (user: User) => void;
};

const UserDialog: React.FC<Props> = ({ open, user, onClose, onSubmit }) => {
  return (
    <Dialog
      open={open}
      onClose={onClose}
      maxWidth="sm"
      fullWidth
      PaperProps={{
        sx: {
          backgroundColor: '#102840',
          borderRadius: 2,
          p: 2
        }
      }}
    >
      <DialogTitle sx={{ color: '#90CAF9' }}>
        {user ? '编辑用户' : '创建新用户'}
      </DialogTitle>
      <DialogContent>
        <UserCRUDForm
          user={user}
          onSubmit={(formData) => {
            onSubmit(formData);
            onClose();
          }}
          onCancel={onClose}
        />
      </DialogContent>
    </Dialog>
  );
};

export default UserDialog;
